if(!dojo._hasResource["market.widgets.Ajax"]){
dojo._hasResource["market.widgets.Ajax"]=true;
dojo.provide("market.widgets.Ajax");
require(["dojo/_base/declare","dojo/html","dijit/_Widget"],function(declare,html,_widget){
declare("market.widgets.Ajax",[_widget],{
ajaxUrl:"",contentId:"",callback:null,form:{},hasCache:false,postData:"",
clear:function(args){
   if(args==null) args={};
   this.ajaxUrl=args.ajaxUrl;
   this.contentId=args.contentId;
   this.callback=args.callback;
   this.form=args.form;
   this.hasCache=args.hasCache;
   this.postData=args.postData;
},
_commonCallXhr:function(handleAsText){
   var _targetNode = this.contentId;
   var cacheWidget = SYSTEMWIDGET.cacheWidget();
   var datasource = null;
   if (this.hasCache && cacheWidget.containKey(this.ajaxUrl)){
      datasource = cacheWidget.getValue(this.ajaxUrl);
   }
   if (datasource == null){
      commonAjax = this;
      dojo.xhrGet({
         url: this.ajaxUrl, handleAs: handleAsText, callback: this.callback,
         load: function(data) {
            if (commonAjax.hasCache){
               SYSTEMWIDGET.cacheWidget().addItem(commonAjax.ajaxUrl, data);
            }
            if (this.handleAs=="text"){
               html.set(_targetNode,data,{parseContent: true});
            }
            if (this.callback!=null){ 
               this.callback(data); 
            }
         },
         error: function(error){
            html.set(_targetNode,"An unexpected error occurred: " + error);
         }
      });
   }else {
      html.set(_targetNode,datasource,{parseContent: true});
      if (this.callback != null){ 
         this.callback(data); 
      }
   }
},
callXhrGet:function(){
   this._commonCallXhr("text");
},
callXhrGetJson:function(){
   this._commonCallXhr("json");
},
callXhrPostForm:function(){
   var _targetNode = this.contentId;
   var xhrArgs = {
    form: this.form,
    handleAs: "json",
    callback: this.callback,
    load: function(data) {
      if (this.callback != null){
         this.callback(data);
      }
    },
    error: function(error) {
       html.set(_targetNode, "An unexpected error occurred: " + error);
    }
   };
   dojo.xhrPost(xhrArgs);
},
callXhrPostJSON:function(){
   var xhrArgs = {
      url:this.ajaxUrl,
      handleAs:"json",
      callback:this.callback,
      postData:this.postData,
      load:function(data) {
         SYSTEMWIDGET.messageWidget().showSucc(data.messageSucc);
         if (this.callback != null){
            this.callback(data);
         }
      },
      error:function(error) {
         SYSTEMWIDGET.messageWidget().showError("An unexpected error occurred: " + error);
      }};
   dojo.xhrPost(xhrArgs);
}
});});}